package com.ruoyi.web.controller.yf;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yf.domain.YfDeptReport;
import com.ruoyi.yf.service.IYfDeptReportService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 医院报模版关系Controller
 * 
 * @author XiaoYi...
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/yf/report")
public class YfDeptReportController extends BaseController
{
    private String prefix = "yf/report";

    @Autowired
    private IYfDeptReportService yfDeptReportService;

    @RequiresPermissions("yf:report:view")
    @GetMapping()
    public String report()
    {
        return prefix + "/report";
    }

    /**
     * 查询医院报模版关系列表
     * eedb1786-64e7-47f8-8305-1d08c6fd0f58
     */
    @RequiresPermissions("yf:report:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YfDeptReport yfDeptReport)
    {
        startPage();
        List<YfDeptReport> list = yfDeptReportService.selectYfDeptReportList(yfDeptReport);
        return getDataTable(list);
    }

    /**
     * 导出医院报模版关系列表
     * b63fd6ff-2982-44ae-94a3-b288a08035e8
     */
    @RequiresPermissions("yf:report:export")
    @Log(title = "医院报模版关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YfDeptReport yfDeptReport)
    {
        List<YfDeptReport> list = yfDeptReportService.selectYfDeptReportList(yfDeptReport);
        ExcelUtil<YfDeptReport> util = new ExcelUtil<YfDeptReport>(YfDeptReport.class);
        return util.exportExcel(list, "report");
    }

    /**
     * 新增医院报模版关系
     * 09cf316d-68b2-4422-b25f-923ff5f1b689
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存医院报模版关系
     * 0d0334c9-3872-48d4-8ec9-1d9d508843e7
     */
    @RequiresPermissions("yf:report:add")
    @Log(title = "医院报模版关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YfDeptReport yfDeptReport)
    {
        return toAjax(yfDeptReportService.insertYfDeptReport(yfDeptReport));
    }

    /**
     * 修改医院报模版关系
     * 26fa672e-edf7-4a90-8f90-ba653d87a9df
     */
    @GetMapping("/edit/{deptId}")
    public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap)
    {
        YfDeptReport yfDeptReport = yfDeptReportService.selectYfDeptReportById(deptId);
        mmap.put("yfDeptReport", yfDeptReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存医院报模版关系
     * 8e1bcb66-9642-4c83-8c50-d87647caad7a
     */
    @RequiresPermissions("yf:report:edit")
    @Log(title = "医院报模版关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YfDeptReport yfDeptReport)
    {
        return toAjax(yfDeptReportService.updateYfDeptReport(yfDeptReport));
    }

    /**
     * 删除医院报模版关系
     * 74bc7a77-cae9-42f9-b88f-da785d47f1fb
     */
    @RequiresPermissions("yf:report:remove")
    @Log(title = "医院报模版关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yfDeptReportService.deleteYfDeptReportByIds(ids));
    }
}
